var db = require("../util/DataBase.js")

module.exports = {
  getArticleId(replyId, success, error) {

    db.query("SELECT `article_id` FROM reply WHERE `id` = ?", [
      replyId
    ], function (err, results) {
      if(err) {
        error && error("获取评论文章ID失败")
      } else {
        success && success(results[0].article_id);
      }
    });

  },
  goodCount(replyId, success, error) {
    db.query("SELECT count(`id`) as `good_count` FROM `reply_good` WHERE `reply_id` = ?", [
      replyId
    ], function (err, results) {
      if(err) {
        error && error("获取点赞数失败")
      } else {
        success && success(results[0].good_count);
      }
    });
  },
  isUserReplyGood(replyId, userId, success, error) {

    db.query("SELECT `id` FROM reply_good WHERE `user_id` = ? AND `reply_id` = ?", [
      userId,
      replyId
    ], function(err, results) {
      if(err) {
        error && error("获取点赞数状态失败")
      } else {

        if(results.length > 0) {
          success && success(true);
        } else {
          success && success(false);
        }

      }
    });

  }
}
